<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="id:" prop="id.value">
                            <el-input v-model="queryParams.id.value" placeholder="请输入id" clearable />
                        </el-form-item>
                    </el-col> -->
                    <el-col :md="6" :sm="12">
                        <el-form-item label="店铺:" prop="site_id.value">
                            <SelectPage v-model="queryParams.site_id.value" :url="'/admin/site/selectPage'" show_field="name" query_field="name" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="运营:" prop="admin_id.value">
                            <SelectPage v-model="queryParams.admin_id.value" :url="'/admin/system.admin/selectPage'" show_field="nickname" query_field="nickname" :filter="{group_id:{value:6,op:'='}}" :multiple="false" />
                        </el-form-item>
                    </el-col>

                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <!-- <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col> -->
                <el-col :span="1.5">
                    <!-- <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button> -->
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <el-row>
                <template>
                    <el-table
                    :data="tableData"
                    border
                    :default-sort = "{prop: 'date', order: 'descending'}"
                    style="width: 100%">
                            <el-table-column
                                prop="id"
                                label="id">
                            </el-table-column>
                            <el-table-column
                                prop="advertiser_title"
                                label="广告账户">
                            </el-table-column>
                            <el-table-column
                                prop="site_title"
                                label="店铺">
                            </el-table-column>
                            <el-table-column
                                prop="admin_title"
                                label="运营">
                            </el-table-column>
                            <el-table-column
                                prop="createtime"
                                label="开始时间">
                            </el-table-column>
                            <el-table-column
                                prop="updatetime"
                                label="结束时间">
                            </el-table-column>
                            <el-table-column label="状态" align="center" key="status">
                                <template slot-scope="scope">
                                    <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0" @change="handleStatusChange(scope.row)"></el-switch>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                                <template slot-scope="scope">
                                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="api.edit">修改</el-button>
                                </template>
                            </el-table-column>
                    </el-table>
                </template>
            </el-row>

            <!-- 列表 -->

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
        <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen" :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData" :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>
    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },

    data() {
        return {
            // table结构
            columns: [
                {
                    visible: true,
                    label: 'id',
                    prop: 'id',
                },
                {
                    visible: true,
                    label: '广告账户',
                    prop: 'advertiser_title',
                },
                {
                    visible: true,
                    label: '店铺',
                    prop: 'site_title',
                },
                // {
                //     visible: true,
                //     label: '店铺类型',
                //     prop: 'type',
                //     component: 'QuickAdminTag',
                //     formatter: (prop, row) => {
                //         return row.type
                //     },
                // },
                {
                    visible: true,
                    label: '运营',
                    prop: 'admin_title',
                },
                {
                    visible: true,
                    label: '开始时间',
                    prop: 'createtime',
                },
                {
                    visible: true,
                    label: '结束时间',
                    prop: 'updatetime',
                },
                {
                    visible: true,
                    label: '类型',
                    prop: 'advplat_type',
                    component: 'QuickAdminTag',
                    formatter: (prop, row) => {
                        if(row.advplat_type == 2){
                            row.advplat_type = '未知'
                        }
                        if(row.advplat_type == 1){
                            row.advplat_type = '手动添加'
                        }
                        if(row.advplat_type == 0){
                            row.advplat_type = 'API'
                        }
                        return row.advplat_type
                    },
                },
            ],
            // 接口地址
            api: {
                index: `/admin/advaccountlog/index`,
                find: `/admin/advaccountlog/find`,
                add: `/admin/advaccountlog/add`,
                edit: `/admin/advaccountlog/edit`,
                delete: `/admin/advaccountlog/delete`,
                export: `/admin/advaccountlog/export`,
                processed: `/admin/advaccountlog/processed`,
                status: `/admin/advaccountlog/status`,
            },
            editFormParams: {},
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
            //是否展示搜索
            showSearch: true,
            // 查询参数
            queryParams: {
                id: { value: undefined, op: '=' },
                admin_id: { value: undefined, op: '=' },
                site_id: { value: undefined, op: '=' },
                createtime: { value: [], op: 'range' },
                updatetime: { value: [], op: 'range' },
            },
        }
    },
    created() {
        this.initIndex()
    },
    watch: {},
    methods: {
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },
        // 菜单状态修改
        handleStatusChange(row) {
            const text = row.status === 0 ? '停用' : '起用'
            this.$confirm(`确认要"${text}"吗?`, '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    this.processeds(row)
                })
                .catch(() => {
                    
                })
        },
        async processeds(row) {
            await this.request.get(this.api.processed, { params: { id:row.id } })
            this.initIndex()
            this.msgSuccess('操作成功')
        },
    },
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
</style>
